package real.evaluation;

import java.util.HashMap;

import real.lang.RealLangException;
import real.lang.RealObject;
import real.lang.RealSet;
import real.utils.RealEvent;
import real.utils.RealEventArgs;

public class Evaluator {

	public static final String CONSTR_VAR_NAME = "construction"; 
	
	private HashMap<String, Evaluable<RealSet>> symbols = new HashMap<String, Evaluable<RealSet>>();
	

	public RealObject getSymbol(String name) throws RealEvaluationException, RealLangException
	{
		return this.symbols.get(name).Evaluate(this);		
	}
	
	
	private HashMap<String, SyntacticalConstruction<? extends RealObject>> symbolBinding;
	
	/**
	 * @param symbolBinding the symbolBinding to set
	 */
	public void setSymbolBinding(String symbolName, SyntacticalConstruction<? extends RealObject> construction) {
		this.symbolBinding.put(symbolName, construction);
	}
	
	/**
	 * @return the symbolBinding
	 */
	public SyntacticalConstruction<? extends RealObject> getSymbolBinding(String symbolName) {
		return symbolBinding.get(symbolName);
	}
	
	public RealEvent OnConstructionEvaluationBegin = new RealEvent();
	
	public RealEvent OnConstructionEvaluationEnd = new RealEvent();
	
	public void BeginConstructionEvaluation(SyntacticalConstruction<? extends RealObject> construction) throws Exception
	{
		if (OnConstructionEvaluationBegin != null) {			
			RealEventArgs e = new RealEventArgs();
			e.put("construction", construction);
			OnConstructionEvaluationBegin.fire(e);
		}
	}
	
	public void EndConstructionEvaluation(SyntacticalConstruction<? extends RealObject> construction) throws Exception
	{
		if (OnConstructionEvaluationEnd != null) {			
			RealEventArgs e = new RealEventArgs();
			e.put(CONSTR_VAR_NAME, construction);
			OnConstructionEvaluationEnd.fire(e);
		}
	}
	
}


